package com.itdfq.springboot_swagger.config;

import com.itdfq.springboot_swagger.controller.DemoController;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @Author GocChin
 * @Date 2021/6/7 18:22
 * @Blog: itdfq.com
 * @QQ: 909256107
 * @Descript:
 */
@Configuration
@EnableSwagger2 //开启Swagger2
public class Swagger {

    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }
    @Bean
    public Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("B");
    }
    @Bean
    public Docket docket3(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("C");
    }

    //配置实例
    @Bean
    public Docket docket(){  //参数获取当前环境
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(info()) //作者
//                .enable(false)  //关闭Swagger
                .groupName("大神钦")//配置默认组
                //下面是一套的东西
                .select()
                //配置扫描文件路径
                /**
                 * basePackage:指定扫描的包
                 * any（）:扫描全部
                 * none():都不扫描
                 * withClassAnnotation:扫描类上的注解  参数是一个注解的反射对象
                 * withMethodAnnotation:扫描方法上的注解
                 */
//                .apis(RequestHandlerSelectors.basePackage("com.itdfq.springboot_swagger.controller"))
//                .apis(RequestHandlerSelectors.withMethodAnnotation(GetMapping.class))
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
//                .paths(PathSelectors.ant("/itdfq/**"))  //过滤什么路径 没有/itdfq/**的就扫描不到了
                .build()
                ;
    }
    //配置Swagger信息
    private ApiInfo info(){
        //作者信息
        Contact contact = new Contact("GodChin","http://itdfq.com","909256107@qq.com");
        return new ApiInfo(
                "Swaager日志",
                "学习Swagger2",
                "v1.0",
                "http://itdfq.com",
                contact,"Gitee",
                "https://gitee.com/godchin",
                new ArrayList<>());
    }
}
